// pages/adviserDetail/adviserDetail.js
var common = require("../../utils/common.js");
//index.js
//获取应用实例
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    data: [],
    getUserInfoFail: false,
    hasData:true,
    options:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log("onLoad")
    var that = this;
    that.setData({
      adInf:options
    })
  },
  onShow:function(){
    console.log(this.data.adInf)
    // console.log("onshow")
    // var that = this;
    // if (that.data.options.id){
    //   that.setData({
    //     data: app.globalData.adviserDetail
    //   })
    // }else{
    // wx.getStorage({
    //     key: 'adviser',
    //     success: function (res) {
    //       that.setData({
    //         data: res.data
    //       })
    //       app.globalData.adviserDetail=res.data;
    //       console.log(app);
    //       wx.setNavigationBarTitle({
    //         title: that.data.data.name
    //       });
    //     },
    //   })
    // }
    // var options=that.data.options;
   // console.log(options)
    // if (!options.id) {
    //   wx.getStorage({
    //     key: 'adviser',
    //     success: function (res) {
    //       that.setData({
    //         data: res.data
    //       })
    //       wx.setNavigationBarTitle({
    //         title: that.data.data.name
    //       });
    //     },
    //   })
    // } 
    
    // else {
    //   common.ajaxPost(
    //     'portal/wlpCounselor/queryCounselorPage.action',
    //     {
    //       id: options.id,
    //       bid: app.globalData.bid
    //     },
    //     function (res) {
    //       console.log(res)
    //       if (res && res.length > 0) {
    //         that.setData({
    //           data: res.data[0]
    //         })
    //         if (res.recordsTotal == 0) {
    //           wx.showToast({
    //             title: '暂无此顾问数据',
    //             icon: 'none'
    //           })
    //           that.setData({
    //             hasData: false
    //           })
    //         } else {
    //           wx.setNavigationBarTitle({
    //             title: res.data[0].name
    //           });
    //         }
    //         //that.getList()
    //       }
    //     }
    //   )
    // }
  },
  copy:function(){
    var that=this;
    wx.setClipboardData({
      data: that.data.adInf.weixin,
      success: function (res) {
        wx.getClipboardData({
          success: function (res) {
            console.log(res.data) // data
          }
        })
      }
    })
  },
  call:function(){
    var that=this;
    wx.makePhoneCall({
      phoneNumber: that.data.adInf.phone //仅为示例，并非真实的电话号码
    })
  },
  onShareAppMessage: function (res) {
    var that=this;
    var xcxids;
    if (app.globalData.xcxshareid) {
      xcxids = app.globalData.xcxshareid
    } else {
      xcxids = app.globalData.queryWlpXcxByParams[0].id
    }


    return {
      title: this.data.adInf.name,
      path: '/pages/index/index?type=adviserDetail&bid=' + app.globalData.bid + "&isIndex=1" + '&headimage=' + that.data.adInf.headimage + '&name=' + that.data.adInf.name + '&id=' + that.data.adInf.id + ' &usertype=' + that.data.adInf.usertype + '&hasNoReceive=' + that.data.adInf.hasNoReceive + '&position=' + that.data.adInf.position + '&weixin=' + that.data.adInf.weixin + '&weixinQrcode=' + that.data.adInf.weixinQrcode + '&phone=' + that.data.adInf.phone + "&xcxid=" + xcxids+"&lpid="+app.globalData.lpid,
      success: function (res) {
        
      },
      fail: function (res) {
        // 转发失败
      }
    }
  },
  onUnload:function () {
    app.globalData.isShareBack = true
    console.log("order退出了")
  }
})